package com.wyw.hemerocallis.controller;

import com.wyw.hemerocallis.service.AuthorityFeignClient;
import com.wyw.hemerocallis.service.comunication.UseRibbonService;
import com.wyw.hemerocallis.service.comunication.UserRestTemplateService;
import com.wyw.hemerocallis.vo.JwtToken;
import com.wyw.hemerocallis.vo.UsernameAndPassword;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微服务通信demo
 *
 * @author Mr Wu    yewen.wu.china@gmail.com
 * <p>
 * Update History:
 * Author        Time            Content
 */
@RestController
@RequestMapping("/communucation")
public class CommunicationController {

    private final AuthorityFeignClient authorityFeignClient;
    private final UseRibbonService useRibbonService;
    private final UserRestTemplateService restTemplateService;

    public CommunicationController(UserRestTemplateService restTemplateService, AuthorityFeignClient authorityFeignClient, UseRibbonService useRibbonService) {
        this.restTemplateService = restTemplateService;
        this.useRibbonService = useRibbonService;
        this.authorityFeignClient = authorityFeignClient;
    }

    @PostMapping("/restTemplate")
    public JwtToken getTokenFromAuthorityService(@RequestBody UsernameAndPassword usernameAndPassword) {
        return restTemplateService.getTokenFromAuthorityService(usernameAndPassword);
    }

    @PostMapping("/restTemplateLoadBalance")
    public JwtToken getTokenFromAuthorityServiceWithLoadBalance(@RequestBody UsernameAndPassword usernameAndPassword) {
        return restTemplateService.getTokenFromAuthorityServiceWithLoadBalancer(usernameAndPassword);
    }

    @PostMapping("/ribbon")
    public JwtToken getRibbon(@RequestBody UsernameAndPassword usernameAndPassword) {
        return useRibbonService.getTokenFormAuthorityServiceByRibbon(usernameAndPassword);
    }

    @PostMapping("/thinkingInRibbon")
    public JwtToken getThinkingInRibbon(@RequestBody UsernameAndPassword usernameAndPassword) {
        return useRibbonService.thinkInRibbon(usernameAndPassword);
    }

    @PostMapping("/token-by-feign")
    public JwtToken getTokenByFeign(@RequestBody UsernameAndPassword usernameAndPassword) {
        return authorityFeignClient.getTokenByFeign(usernameAndPassword);
    }






}
